﻿var nav = navigator;
var uat = nav.userAgent;
var MessageHide = false;
var MessageHideSetTimeout;
//info wrong error success
Message_Mini = function (style, text, time)
{
    Message(style, '<div class="s"></div><div class="c">' + text + '</div><div class="e"></div>', time, { "unique": "message", "center": true }, null);
};
Message_Mini2 = function (style, text, time, config, func)
{
    Message(style, '<div class="s"></div><div class="c">' + text + '</div><div class="e"></div>', time, config, func);
};
Message = function (style, html, time, config, func)
{
    if (typeof func != 'function')
    {
        func = function (){};
    }
    config = config ? config : {};
    var id = (config["unique"] ? config["unique"] : random(10));
    if (!html)
        return;
    var jobj = $("#" + id);
    if (jobj.length == 0)
    {
        jobj = $("<div id=\"" + id + "\"></div>");
        $(document.body).append(jobj);
    }
    jobj.attr("class", style);
    jobj.html(html);
    if (config["center"])
    {
        var pos = position(jobj);

        var doc = (document.compatMode && document.compatMode != "BackCompat" && !uat.toLowerCase().indexOf('webkit') > -1) ? document.documentElement : document.body;
        var elStyle = "position:absolute;left:";
        elStyle += (doc.scrollWidth - pos.width) / 2;
        elStyle += "px;top:";
        elStyle += doc.scrollTop + (doc.clientHeight / 2) - (pos.height / 2);
        elStyle += "px";

        jobj.attr("style", elStyle);
    };
    if (time && time > 0)
    {
        clearTimeout(MessageHideSetTimeout);
        MessageHideSetTimeout = window.setTimeout(
            function ()
            {
                $("#" + id).hide();
                if (func && $.isFunction(func))
                {
                    func();
                }
            },
            1000 * time
        );
    }
};
InputBox = function (config, callback)
{
    config = config ? config : {};
    var id = (config["unique"] ? config["unique"] : random(10));
    if (!html)
        return;
    var jobj = $("#" + id);
    if (jobj.length == 0)
    {
        jobj = $("<div id=\"" + id + "\"></div>");
        $(document.body).append(jobj);
    }
    jobj.attr("class", "info");
    jobj.html(html);
    if (config["center"])
    {
        var pos = position(jobj);

        var doc = (document.compatMode && document.compatMode != "BackCompat" && !uat.toLowerCase().indexOf('webkit') > -1) ? document.documentElement : document.body;
        var style = "position:absolute;left:";
        style += (doc.scrollWidth - pos.width) / 2;
        style += "px;top:";
        style += doc.scrollTop + (doc.clientHeight / 2) - (pos.height / 2);
        style += "px";

        jobj.attr("style", style);
    }
    ;
};
function position(jobj)
{
    var position = jobj.position();
    return { "width": jobj.width(), "height": jobj.height(), "top": position.top, "left": position.left };
}
random = function (length, upper, lower, number)
{

    if (!upper && !lower && !number)
    {
        upper = lower = number = true;
    }

    var a = [
			["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"],
			["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"],
			["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
    ];

    //临时数组
    var b = [];

    //临时字串 
    var c = "";

    b = upper ? b.concat(a[0]) : b;
    b = lower ? b.concat(a[1]) : b;
    b = number ? b.concat(a[2]) : b;

    for (var i = 0; i < length; i++)
    {
        c += b[Math.round(Math.random() * (b.length - 1))];
    }
    return c;
}